﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace PPSignSDKDemoForm
{
    public partial class showImageDlg : Form
    {
        //private static string strfile = System.Environment.GetEnvironmentVariable("TEMP");
        private static string strfilename = System.Environment.GetEnvironmentVariable("TEMP") + "\\PPSignTempImage.bmp";
        
        public showImageDlg()
        {
            InitializeComponent();

           if (File.Exists(strfilename))
           {
               Image img = Image.FromFile(strfilename, false);
               MemoryStream ms = new MemoryStream();
               img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
               this.pictureBox1.Image = Image.FromStream(ms);
               img.Dispose();

           }else
           {
                MessageBox.Show("Load Image Failed"/*" 加载签名图像失败或没有生成签名图像！"*/, "PPSignSDKDemo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                SaveBtn.Enabled = false;

           }
           if (panel1.Width > pictureBox1.Width && panel1.Height > pictureBox1.Height)
               this.pictureBox1.Location = new Point((panel1.Width - pictureBox1.Width)/2, (panel1.Height - pictureBox1.Height) / 2);

          
         }

        private void SaveBtn_Click(object sender, EventArgs e)
        {
            string strSrc = strfilename;
            if (File.Exists(strSrc))
            {
                FolderBrowserDialog dlg = new FolderBrowserDialog();
                dlg.SelectedPath = "c:";
                dlg.Description = "请选择保存pfx文件的目录";
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;
                string strDes = dlg.SelectedPath + "\\";
                strDes += "test.bmp";

                File.Copy(strSrc, strDes, true);
            }
            Close();
        }

        private void CancelBtn_Click(object sender, EventArgs e)
        {

        }

        private Point _startLocation;
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _startLocation = e.Location;
                Cursor = Cursors.SizeAll;
            }
            panel1.Focus();
        }
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            Cursor = Cursors.Default;
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                int xOffset = _startLocation.X - e.X;
                int yOffset = _startLocation.Y - e.Y;
                this.panel1.AutoScrollPosition = new Point(this.panel1.HorizontalScroll.Value + xOffset, panel1.VerticalScroll.Value + yOffset);
            }
        }

        private void showImageDlg_Load(object sender, EventArgs e)
        {

        }

 
      
    }
}
